package domain;

import java.util.Collection;
import java.util.HashSet;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;
import org.hibernate.validator.constraints.SafeHtml;
import org.hibernate.validator.constraints.SafeHtml.WhiteListType;

@Entity
@Access(AccessType.PROPERTY)
@Table(uniqueConstraints={@UniqueConstraint(columnNames = { "orderNumber","event_id" })})
public class Route extends DomainEntity {

	// Constructors -----------------------------------------------------------

	public Route() {
		super();
		evaluations = new HashSet<Evaluation>();
	}

	// Attributes -------------------------------------------------------------

	private String name;
	private Double lenght;
	private int difficulty;
	private int orderNumber;
	private Double rating;

	@Range(min = 0, max = 100)
	public Double getRating() {
		return rating;
	}

	public void setRating(Double rating) {
		this.rating = rating;
	}
	@NotBlank
	@SafeHtml(whitelistType = WhiteListType.NONE)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}


	@NotNull
	public Double getLenght() {
		return lenght;
	}

	public void setLenght(Double lenght) {
		this.lenght = lenght;
	}


	@NotNull
	@Range(min = 0, max = 100)
	public Integer getDifficulty() {
		return difficulty;
	}

	public void setDifficulty(Integer difficulty) {
		this.difficulty = difficulty;
	}

	@Min(0)
	public Integer getOrderNumber() {
		return orderNumber;
	}

	public void setOrderNumber(Integer olderNumber) {
		this.orderNumber = olderNumber;
	}

	// Relationships ----------------------------------------------------------

	private Event event;
	private Collection<Evaluation> evaluations;

	@Valid
	@NotNull
	@ManyToOne(optional = false)
	public Event getEvent() {
		return event;
	}

	public void setEvent(Event event) {
		this.event = event;
	}
	
	@Valid
	@NotNull
	@OneToMany(mappedBy="route")
	public Collection<Evaluation> getEvaluations() {
		return evaluations;
	}

	public void setEvaluations(Collection<Evaluation> evaluations) {
		this.evaluations = evaluations;
	}

	
	
}
